package de.hhn.mim.psb;


/**
 * Klasse realisiert einen homogenisierten dreidimensionalen Vektor
 * Wird als Hilfsklasse bei Matrixoperationen (Klasse Matrix3D) verwendet
 * enthaelt Methoden um Vect3D und Arrays in Vect3DH und umgekehrt zu wandeln
 * @author Rolf Bendl
 * 
 * 2012-05-12 Klasse erstellt
 *
 */
public class Vect3DH extends Vect3D
 {
  double w;
  
  public Vect3DH()
   {
    super();
    w = 1;
   }
  public Vect3DH(Vect3D v)
   {
    this(v.x, v.y, v.z);
   }
  
  public Vect3DH(double x, double y, double z)
   {
    super(x, y, z);
    w = 1;
   }
  
  public Vect3DH(double [] array)
   {
    this();
    int error = 0;
    
    if(array.length >= 3)
     {
      x = array[0]; y = array[1]; z = array[2];
      if(array.length == 4) w = array[3];
     }  
    else error = -1;
   }
  
  public Vect3D toVect3D()
   {
    Vect3D result = new Vect3D();
    result.x = x / w;
    result.y = y / w;
    result.z = z / w;
    return result;
   }
  
  public double[] toArray()
   {
    double [] a = new double [4];
    a[0] = x; a[1] = y; a[2] = z; a[3] = w;
    return a;
   }
  
  public void print()
   {
    System.out.printf("x %7.2f  y %7.2f  z %7.2f  w %7.2f\n", x, y, z, w);
   }
  
  public static void main(String[] args)
   {
    Vect3DH v = new Vect3DH(12.343434, 34.565656, 56.7878787);
    v.print();
   }
 }
